//
//  TestVC.m
//  easyVideo-oc
//
//  Created by quanhao huang on 2021/8/5.
//

#import "TestVC.h"

@interface TestVC ()
{
    UIButton *firstButton;
    UIButton *custombutton;
    UIButton *thirdButton;
}
@end

@implementation TestVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self createAButton];
    custombutton = [self createACustomButton:CGRectMake(300, 200, 100, 100) action:@selector(buttonAction:) color:UIColor.yellowColor titleText:@"第二个按钮"];
    [self.view addSubview:custombutton];
    thirdButton = [self createACustomButton:CGRectMake(300, 400, 100, 100) action:@selector(buttonAction:) color:UIColor.yellowColor titleText:@"第二个按钮"];
    [self.view addSubview:thirdButton];
    
}

//创建一个按钮
- (void)createAButton {
//    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
    firstButton.frame = CGRectMake(100, 100, 100, 100);
    [firstButton setTitle:@"按钮" forState:UIControlStateNormal];
    [firstButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    firstButton.backgroundColor = UIColor.redColor;
    [firstButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    
    [self.view addSubview:firstButton];
}

//创建一个自定义按钮
- (UIButton *)createACustomButton:(CGRect)rect action:(SEL)action color:(UIColor *)color titleText:(NSString *)title {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = rect;
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = color;
    [button setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    return button;
}

//按钮方法
- (void)buttonAction:(UIButton *)button {
    if (button == firstButton) {
        NSLog(@"点击了第一个按钮");
    }else if (button == custombutton) {
        NSLog(@"点击了第二个按钮");
    }else if (button == thirdButton) {
        NSLog(@"点击了第三个按钮");
    }
}

- (int)minusa:(int)a b:(int)b {
    return a-b;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
